﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using MediaController.Client.Controls.Dialogs;
using MediaController.Utils;

namespace MediaController
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            using (var spi = new SingleProgramInstance("mediaextractor"))
            {
                if (spi.IsSingleInstance)
                {
                    AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }
                else
                {
                    spi.RaiseOtherProcess();
                }
            }
        }

        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var exception = (Exception)e.ExceptionObject;
            MessageForm.ShowMessageFormException(exception);
        }
    }
}
